package db

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	"go-member/tool"
)

// InitMysql
// @Description:连接Mysql
func InitMysql() *gorm.DB {
	host := tool.GetEnvDefault("mysql-host", "127.0.0.1")
	database := tool.GetEnvDefault("mysql-database", "member")
	name := tool.GetEnvDefault("mysql-name", "root")
	password := tool.GetEnvDefault("mysql-password", "root")
	db, err := gorm.Open("mysql", fmt.Sprintf("%s:%s@(%s:3306)/%s", name, password, host, database))
	if err != nil {
		fmt.Println("数据库连接失败")
		panic(err)
	}
	return db
}
